CC 			= g++
TARGET		= TEST

PLATFORM = armhf
PWD = $(shell pwd)

ROOT = $(PWD)/../../

# 源文件路径, 从root开始
SUBDIR  = ../../src	\
		../../src/Test/Test_libusb \


# 头文件路径
INCLDER = 	-I../../include \
			-I../../src	\
			-I../../src/Test	\
			-I../../src/Test_libusb \
# 动态库路径及动态库
SLIBDIR = -L../../lib/$(PLATFORM)
SLIB	= -lusb-1.0 -lpthread

ifdef DEBUG
CXX_CFLAGS += -g
endif

CXX_CFLAGS 	+= -g $(INCLDER) 
# CXX_CFLAGS 	+= -std=c++11

LD_FLAGS += $(SLIBDIR) $(SLIB)

#####################################################
#           以下配置基本不用修改                       #
#####################################################
# 搜索所有源文件
CXX_SOURCES  = $(foreach src, $(SUBDIR), $(wildcard $(src)/*.cpp))

# 所有object文件
OBJDIR	= obj/
OBJS_TEMP 	= $(patsubst  %.cpp, %.o, $(CXX_SOURCES))
CXX_OBJECTS = $(addprefix $(OBJDIR), $(notdir $(OBJS_TEMP)))

# 所有依赖文件
DEP_FILES   = $(patsubst  %.o,  %.d, $(CXX_OBJECTS))

# 所有cpp文件的搜索路径
vpath %.cpp $(SUBDIR)

# 生成目标文件 
$(TARGET) : $(CXX_OBJECTS)
	$(CC) $(CXX_CFLAGS) -o $@ $^ $(LD_FLAGS)

# 生成object文件
$(OBJDIR)%.o : %.cpp
	@mkdir -p $(OBJDIR)
	$(CC) $(CXX_CFLAGS) -c -MMD $< -o $@
	# $(CC) $(CXX_CFLAGS) -c -MMD -MT $@ -MF $(patsubst %.o, %.d, $@) $< -o $@

# 加入依赖文件
-include $(DEP_FILES)

# 伪目标，all, clean, install, print, tar, dist, TAGS, check/test
.PHONY : print clean all
print :
	@echo $(CXX_SOURCES)
	@echo $(OBJS_TEMP)
	@echo $(CXX_OBJECTS)
clean :
	-rm -rf $(OBJDIR)
	-rm -rf $(TARGET)
all :
	make clean
	make
